package validation.jexp;

import com.jgoodies.binding.adapter.BasicComponentFactory;
import com.jgoodies.binding.value.ValueHolder;
import com.jgoodies.binding.value.ValueModel;
import com.jgoodies.forms.builder.DefaultFormBuilder;
import com.jgoodies.forms.layout.FormLayout;

import javax.swing.*;

/**
 * JGoodies Binding: Basic Component Factory Example
 */
public class BasicComponentFactoryExample extends JPanel {

    public JPanel createPanel() {
        DefaultFormBuilder builder = new DefaultFormBuilder(new FormLayout("p, 2dlu, p:g"));
        builder.setDefaultDialogBorder();
        ValueModel longModel = new ValueHolder();
        ValueModel dateModel = new ValueHolder();
        ValueModel stringModel = new ValueHolder();
        builder.append("Integer Field: ", BasicComponentFactory.createIntegerField(longModel, 3));
        builder.append("Long Field: ", BasicComponentFactory.createLongField(longModel, 2));
        builder.append("Date Field: ", BasicComponentFactory.createDateField(dateModel));
        builder.nextLine();
        builder.append("Text Field: ", BasicComponentFactory.createTextField(stringModel, true));
        builder.append("Password Field: ", BasicComponentFactory.createPasswordField(stringModel, false));
        builder.append("Text Area: ", BasicComponentFactory.createTextArea(stringModel));
        return builder.getPanel();
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> {
            JGoodiesValidationUtils.showFrame("Basic Componet Factory Example", (new BasicComponentFactoryExample()).createPanel());
        });
    }
}
